﻿ 
using System;
using System.Collections.Generic;
using System.Drawing;

namespace 万向焊接单机
{
    public class CamEngine
    {
        public const string CamName = "camera";

        // static HIKCamera camera = new HIKCamera();
        private static HIKCamera camera = null;

        /// <summary>
        /// 上相机
        /// </summary>
        public static HIKCamera CAM
        {
            get
            {
                return camera;
            }
        }

        /// <summary>
        /// 初始化系统相机
        /// </summary>
        /// <param name="windows"></param>
        /// <param name="handler"></param>
        public static void Init(Action<string> manualImage, Action<Bitmap> autoImage)
        {
            List<IntPtr> ls = new List<IntPtr>();
            HIKCamera.EnumDevices(ref ls);
            for (int i = 0; i < ls.Count; i++)
            {
                HIKCamera cam = new HIKCamera();
                if (cam.Init(ls[i]))
                {
                    cam.OnManualImage += manualImage;
                    cam.OnError += Camera_OnError;
                    cam.OnAutoImage += autoImage;
                    //cam.hWindow = window;
                    camera = cam;
                    break;
                }
            }
        }

        /// <summary>
        /// 相机异常
        /// </summary>
        /// <param name="arg1"></param>
        /// <param name="arg2"></param>
        private static void Camera_OnError(string arg1, string arg2)
        {
             
        }

        /// <summary>
        /// 卸载相机
        /// </summary>
        public static void Uninit()
        {
            camera?.Uninit();
        }

        
    }
}
